package com.china.school;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class SqlSessionTest {
    public static  class SysDept{
        private Long id;
        private String deptName;

    }
    public static void main(String[] args) throws IOException {
//        String resource = "E:\\shenniudata\\spring-learning-self\\Spring-IOC\\src\\main\\resources\\mybatis-cofig.xml";
//        InputStream inputStream = Resources.getResourceAsStream(resource);
//        SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
//
//        SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(inputStream);
//        SqlSession sqlSession = sqlSessionFactory.openSession();
//        sqlSession.select("select * from sys_dept",(resultContext)->{
//            List<SysDept> list = new ArrayList<>();
//            Object resultObject = resultContext.getResultObject();
//            System.out.println(resultObject.getClass());
//            for (int i = 0; i < resultContext.getResultCount(); i++) {
//
//            }
//        });


        ApplicationContext ctx = new ClassPathXmlApplicationContext("SqlSessionTest.xml");
        System.out.println(ctx.getBean("sqlSessionFactory"));
//        SqlSession   sqlSession = (SqlSession) ctx.getBean("sqlSession");
//        sqlSession.select("select * from sys_dept",(resultContext)->{
//            List<SysDept> list = new ArrayList<>();
//            Object resultObject = resultContext.getResultObject();
//            System.out.println(resultObject.getClass());
//            for (int i = 0; i < resultContext.getResultCount(); i++) {
//
//            }
//        });

    }
}
